﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:markup="clr-namespace:Elysium.Markup"
                    xmlns:params="clr-namespace:Elysium.Parameters">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/Themes/SharedResources.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Style TargetType="{x:Type TabControl}">
        <Setter Property="Background" Value="{markup:ThemeResource BackgroundBrush}"/>
        <Setter Property="BorderBrush" Value="{markup:ThemeResource HighlightBrush}"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="params:TabControl.IndicatorBrush" Value="{markup:ThemeResource PaleBrush}"/>
        <Setter Property="Foreground" Value="{markup:ThemeResource ForegroundBrush}"/>
        <Setter Property="FontSize" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.TextFontSize), Mode=OneWay}"/>
        <Setter Property="FontStretch" Value="Medium"/>
        <Setter Property="FontStyle" Value="Normal"/>
        <Setter Property="FontWeight" Value="Normal"/>
        <Setter Property="TextOptions.TextFormattingMode" Value="Display"/>
        <Setter Property="TextOptions.TextRenderingMode" Value="ClearType"/>
        <Setter Property="RenderOptions.ClearTypeHint" Value="Enabled"/>        
        <Setter Property="ClipToBounds" Value="True"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
        <Setter Property="Padding" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.BoldPadding), Converter={StaticResource ThicknessConverter}, ConverterParameter='Top', Mode=OneWay}"/>
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>        
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabControl}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            TextBlock.Foreground="{TemplateBinding Foreground}"
                            TextBlock.FontFamily="{TemplateBinding FontFamily}"
                            TextBlock.FontSize="{TemplateBinding FontSize}"
                            TextBlock.FontStretch="{TemplateBinding FontStretch}"
                            TextBlock.FontStyle="{TemplateBinding FontStyle}"
                            TextBlock.FontWeight="{TemplateBinding FontWeight}"
                            TextOptions.TextFormattingMode="{TemplateBinding TextOptions.TextFormattingMode}"
                            TextOptions.TextRenderingMode="{TemplateBinding TextOptions.TextRenderingMode}"
                            RenderOptions.ClearTypeHint="{TemplateBinding RenderOptions.ClearTypeHint}"
                            KeyboardNavigation.DirectionalNavigation="Local"
                            ClipToBounds="{TemplateBinding ClipToBounds}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition x:Name="FirstColumnDefinition"
                                                  Width="*"/>
                                <ColumnDefinition x:Name="SecondColumnDefinition"
                                                  Width="0"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition x:Name="FirstRowDefinition"
                                               Height="Auto"/>
                                <RowDefinition x:Name="SecondRowDefinition"
                                               Height="*"/>
                            </Grid.RowDefinitions>
                            <Rectangle x:Name="Indicator"
                                       Grid.Column="0"
                                       Grid.Row="0"
                                       Fill="{TemplateBinding params:TabControl.IndicatorBrush}"
                                       Height="{TemplateBinding params:TabControl.IndicatorThickness}"
                                       HorizontalAlignment="Stretch"
                                       VerticalAlignment="Bottom"/>
                            <TabPanel x:Name="HeaderPanel"
                                      Grid.Column="0"
                                      Grid.Row="0"
                                      IsItemsHost="True"
                                      KeyboardNavigation.TabIndex="1" />
                            <Border x:Name="ContentPanel"
                                    Grid.Column="0"
                                    Grid.Row="1"
                                    Background="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem.(TabItem.Background)}"
                                    BorderBrush="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem.(TabItem.BorderBrush)}"
                                    BorderThickness="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem.(TabItem.BorderThickness)}"
                                    TextBlock.Foreground="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem.(TabItem.Foreground)}"
                                    TextBlock.FontFamily="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem.(TabItem.FontFamily)}"
                                    TextBlock.FontSize="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem.(TabItem.FontSize)}"
                                    TextBlock.FontStretch="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem.(TabItem.FontStretch)}"
                                    TextBlock.FontStyle="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem.(TabItem.FontStyle)}"
                                    TextBlock.FontWeight="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem.(TabItem.FontWeight)}"
                                    TextOptions.TextFormattingMode="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem.(TextOptions.TextFormattingMode)}"
                                    TextOptions.TextRenderingMode="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem.(TextOptions.TextRenderingMode)}"
                                    RenderOptions.ClearTypeHint="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem.(RenderOptions.ClearTypeHint)}"
                                    KeyboardNavigation.DirectionalNavigation="Contained"
                                    KeyboardNavigation.TabIndex="2"
                                    KeyboardNavigation.TabNavigation="Local">
                                <ContentPresenter x:Name="PART_SelectedContentHost"
                                                  ContentSource="SelectedContent"
                                                  Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem.(TabItem.Padding)}"
                                                  HorizontalAlignment="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem.(TabItem.HorizontalContentAlignment), Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                                                  VerticalAlignment="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem.(TabItem.VerticalContentAlignment), Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"/>
                            </Border>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="TabStripPlacement" Value="Bottom">
                            <Setter TargetName="FirstRowDefinition" Property="Height" Value="*"/>
                            <Setter TargetName="SecondRowDefinition" Property="Height" Value="Auto"/>
                            <Setter TargetName="Indicator" Property="Grid.Row" Value="1"/>
                            <Setter TargetName="HeaderPanel" Property="Grid.Row" Value="1"/>
                            <Setter TargetName="ContentPanel" Property="Grid.Row" Value="0"/>
                            <Setter TargetName="Indicator" Property="VerticalAlignment" Value="Top"/>
                        </Trigger>
                        <Trigger Property="TabStripPlacement" Value="Left">
                            <Setter TargetName="FirstColumnDefinition" Property="Width" Value="Auto"/>
                            <Setter TargetName="SecondColumnDefinition" Property="Width" Value="*"/>
                            <Setter TargetName="FirstRowDefinition" Property="Height" Value="*"/>
                            <Setter TargetName="SecondRowDefinition" Property="Height" Value="0"/>
                            <Setter TargetName="Indicator" Property="Grid.Column" Value="0"/>
                            <Setter TargetName="HeaderPanel" Property="Grid.Column" Value="0"/>
                            <Setter TargetName="ContentPanel" Property="Grid.Column" Value="1"/>
                            <Setter TargetName="Indicator" Property="Grid.Row" Value="0"/>
                            <Setter TargetName="HeaderPanel" Property="Grid.Row" Value="0"/>
                            <Setter TargetName="ContentPanel" Property="Grid.Row" Value="0"/>
                            <Setter TargetName="Indicator" Property="Width" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:TabControl.IndicatorThickness)}"/>
                            <Setter TargetName="Indicator" Property="Height" Value="NaN"/>
                            <Setter TargetName="Indicator" Property="HorizontalAlignment" Value="Right"/>
                            <Setter TargetName="Indicator" Property="VerticalAlignment" Value="Stretch"/>
                        </Trigger>
                        <Trigger Property="TabStripPlacement" Value="Right">
                            <Setter TargetName="FirstColumnDefinition" Property="Width" Value="*"/>
                            <Setter TargetName="SecondColumnDefinition" Property="Width" Value="Auto"/>
                            <Setter TargetName="FirstRowDefinition" Property="Height" Value="*"/>
                            <Setter TargetName="SecondRowDefinition" Property="Height" Value="0"/>
                            <Setter TargetName="Indicator" Property="Grid.Column" Value="1"/>
                            <Setter TargetName="HeaderPanel" Property="Grid.Column" Value="1"/>
                            <Setter TargetName="ContentPanel" Property="Grid.Column" Value="0"/>
                            <Setter TargetName="Indicator" Property="Grid.Row" Value="0"/>
                            <Setter TargetName="HeaderPanel" Property="Grid.Row" Value="0"/>
                            <Setter TargetName="ContentPanel" Property="Grid.Row" Value="0"/>
                            <Setter TargetName="Indicator" Property="Width" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:TabControl.IndicatorThickness)}"/>
                            <Setter TargetName="Indicator" Property="Height" Value="NaN"/>
                            <Setter TargetName="Indicator" Property="HorizontalAlignment" Value="Left"/>
                            <Setter TargetName="Indicator" Property="VerticalAlignment" Value="Stretch"/>
                        </Trigger>
                    </ControlTemplate.Triggers>                    
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=FontSize, Mode=OneWay, Converter={StaticResource IsGreaterThanConverter}, ConverterParameter=18}">
                <Setter Property="TextOptions.TextFormattingMode" Value="Ideal"/>
            </DataTrigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="BorderBrush" Value="{markup:ThemeResource DisabledBrush}"/>
                <Setter Property="Foreground" Value="{markup:ThemeResource DisabledBrush}"/>
            </Trigger>            
        </Style.Triggers>        
    </Style>

</ResourceDictionary>